package it.kion.util.ui.ulog2.editor.scanners;

import it.kion.util.ui.ulog2.Log4jPlugin;
import it.kion.util.ui.ulog2.editor.TokenManager;

import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;

public class ValueScanner extends RuleBasedScanner
{
   String[] keywords =
      {
         "ALL",
         "DEBUG",
         "ERROR",
         "FATAL",
         "INFO",
         "OFF",
         "WARN",
         "INHERITED",
         "INHERIT",
         "NULL",
         "true",
         "false",
         };

   public ValueScanner(TokenManager tokenManager)
   {
      IToken defaultToken =
         tokenManager.getToken(Log4jPlugin.PREF_DEFAULT_COLOR);
      IToken formatToken =
         tokenManager.getToken(Log4jPlugin.PREF_FORMAT_COLOR);
      IToken keywordToken =
         tokenManager.getToken(Log4jPlugin.PREF_KEYWORD_COLOR);

      IRule braceRule =
         new SingleLineRule("{", "}", formatToken, (char) 0, true);

      WordRule keywordRule = new WordRule(new WordDetector());
      for (int i = 0; i < keywords.length; i++)
      {
         keywordRule.addWord(keywords[i], keywordToken);
      }

      IRule formatRule = new FormatRule(formatToken);

      IRule whitespaceRule =
         new WhitespaceRule(new WhitespaceDetector());

      setDefaultReturnToken(defaultToken);
      setRules(
         new IRule[] {
            braceRule,
            formatRule,
            keywordRule,
            whitespaceRule,
            });
   }
}
